﻿using System;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityStandardAssets.ImageEffects;

// Token: 0x02000382 RID: 898
[RequireComponent(typeof(PostProcessingBehaviour))]
public class ImageEffectConfigChanger : MonoBehaviour
{
	// Token: 0x0600163F RID: 5695 RVA: 0x0009503C File Offset: 0x0009323C
	private void Start()
	{
		this.postProcessingBehaviour = base.GetComponent<PostProcessingBehaviour>();
		this.ssao = base.GetComponent<SSAOPro>();
		this.dof = base.GetComponent<DepthOfField>();
		for (int i = 0; i < this.profileSets.Length; i++)
		{
			this.profileSets[i].Setup();
		}
		this.ChangeConfig();
	}

	// Token: 0x06001640 RID: 5696 RVA: 0x0009509C File Offset: 0x0009329C
	public void ChangeConfig()
	{
		if (this.profileNo != ConfigData.postProcessFlavor)
		{
			this.profileNo = ConfigData.postProcessFlavor;
			UnityEngine.Object.Destroy(this.instantiateProfile);
			this.instantiateProfile = UnityEngine.Object.Instantiate<PostProcessingProfile>(this.profileSets[this.profileNo].profile);
			this.instantiateProfile.name = "InstantiateProfile";
			this.postProcessingBehaviour.profile = this.instantiateProfile;
		}
		this.instantiateProfile.bloom.enabled = ConfigData.bloomEnable;
		BloomModel.Settings settings = this.instantiateProfile.bloom.settings;
		settings.bloom.intensity = this.profileSets[this.profileNo].bloomIntensity * ConfigData.bloomRate;
		settings.lensDirt.texture = ((!ConfigData.lensDirtEnable) ? null : this.dirtTex);
		this.instantiateProfile.bloom.settings = settings;
		if (this.instantiateProfile.eyeAdaptation.enabled != ConfigData.eyeAdaptationEnable)
		{
			this.instantiateProfile.eyeAdaptation.enabled = ConfigData.eyeAdaptationEnable;
		}
		EyeAdaptationModel.Settings settings2 = this.instantiateProfile.eyeAdaptation.settings;
		settings2.exposureCompensation = 0.6f + Mathf.Lerp(-0.2f, 0.2f, ConfigData.exposureCompensation);
		this.instantiateProfile.eyeAdaptation.settings = settings2;
		this.postProcessingBehaviour.EyeAdaptation.ResetHistory();
		this.instantiateProfile.vignette.enabled = ConfigData.vignetteEnable;
		VignetteModel.Settings settings3 = this.instantiateProfile.vignette.settings;
		settings3.intensity = this.profileSets[this.profileNo].vignetteIntensity * ConfigData.vignetteRate;
		this.instantiateProfile.vignette.settings = settings3;
		this.instantiateProfile.chromaticAberration.enabled = ConfigData.noiseEnable;
		ChromaticAberrationModel.Settings settings4 = this.instantiateProfile.chromaticAberration.settings;
		settings4.intensity = this.profileSets[this.profileNo].chromaticAberrationIntensity * ConfigData.noiseRate;
		this.instantiateProfile.chromaticAberration.settings = settings4;
		this.instantiateProfile.grain.enabled = ConfigData.noiseEnable;
		GrainModel.Settings settings5 = this.instantiateProfile.grain.settings;
		settings5.intensity = this.profileSets[this.profileNo].grainIntensity * ConfigData.noiseRate;
		this.instantiateProfile.grain.settings = settings5;
		if (this.ssao != null)
		{
			this.ssao.enabled = ConfigData.ssaoEnable;
			this.ssao.Intensity = 1f * ConfigData.ssaoIntensity;
			this.ssao.Radius = 0.12f * ConfigData.ssaoRadius;
		}
		if (this.dof != null && this.dofChange)
		{
			this.dof.enabled = ConfigData.dofEnable;
			this.dof.aperture = Mathf.Lerp(0.6f, 0.9f, ConfigData.dofRate);
		}
	}

	// Token: 0x040019F8 RID: 6648
	private PostProcessingBehaviour postProcessingBehaviour;

	// Token: 0x040019F9 RID: 6649
	private SSAOPro ssao;

	// Token: 0x040019FA RID: 6650
	private DepthOfField dof;

	// Token: 0x040019FB RID: 6651
	public ProfileSet[] profileSets;

	// Token: 0x040019FC RID: 6652
	public Texture dirtTex;

	// Token: 0x040019FD RID: 6653
	private int profileNo = -1;

	// Token: 0x040019FE RID: 6654
	public bool dofChange = true;

	// Token: 0x040019FF RID: 6655
	private PostProcessingProfile instantiateProfile;
}
